package Chuong04;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.text.StyledEditorKit.FontSizeAction;

public class Bai09 extends JFrame implements ActionListener{
	
	JTextArea tta = new JTextArea("Sample Text",10,30);
	JCheckBox jcbDam = new JCheckBox("Chữ đậm");
	JCheckBox jcbNghieng = new JCheckBox("Chữ nghiêng");
	JCheckBox jcbGhachChan = new JCheckBox("Ghạch chân");
	
	public Bai09(){
		setSize(600, 300);
	    setTitle("Bài 09 - Chương 04");
	    jcbDam.addActionListener(this);
	    jcbNghieng.addActionListener(this);
	    jcbGhachChan.addActionListener(this);
	    JPanel p = new JPanel();
	    
	    tta.setFont(new Font("Tahoma", Font.PLAIN, 18));
	    
	    JPanel p1 = new JPanel();
	    p1.add(jcbDam);p1.add(jcbNghieng);p1.add(jcbGhachChan);
	    
	    p.add(tta);
	    p.add(p1);
	    add(p);	    
	}
	
	public static void main(String[] args) {
		Bai09 frm = new Bai09();
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frm.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		
		if(e.getSource() == jcbDam || e.getSource() == jcbNghieng || e.getSource() == jcbGhachChan){
			Font f = null;
			if(jcbDam.isSelected() && jcbNghieng.isSelected() && jcbGhachChan.isSelected()){
				f = new Font("Tahoma", Font.BOLD + Font.ITALIC, 18);
			}else if(jcbDam.isSelected() && jcbNghieng.isSelected()){
				f = new Font("Tahoma", Font.BOLD + Font.ITALIC, 18);
			}else if(jcbDam.isSelected() && jcbGhachChan.isSelected()){
				f = new Font("Tahoma", Font.BOLD + Font.ITALIC, 18);
			}else if(jcbGhachChan.isSelected() && jcbNghieng.isSelected()){
				f = new Font("Tahoma", Font.ITALIC, 18);
			}else if(jcbDam.isSelected()){
				f = new Font("Tahoma", Font.BOLD, 18);
			}else if(jcbNghieng.isSelected()){
				f = new Font("Tahoma", Font.ITALIC, 18);
			}else if(jcbGhachChan.isSelected()){
				f = new Font("Tahoma", Font.BOLD + Font.ITALIC, 18);
			}else{
				f = new Font("Tahoma", Font.PLAIN, 18);
			}			
			tta.setFont(f);
		}
		
	}

}
